#include <bits/stdc++.h>

using namespace std;

int t;
int n, m, l, k;
int d[100005], v[100005], a[100005];
int p[100005];
int prv[1000005], nxt[1000005];
vector<pair<int, int>> s;
int fenwick[100005];

inline void add(int x) {
	for (; x <= m; x += x & -x)
		fenwick[x]++;
}

inline int query(int r) {
	int res = 0;
	for (; r != 0; r -= r & -r)
		res += fenwick[r];
	return res;
}

int main() {
	freopen("detect.in", "r", stdin);
	freopen("detect.out", "w", stdout);
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	for (cin >> t; t--; ) {
		cin >> n >> m >> l >> k;
		for (int i = 1; i <= n; i++)
			cin >> d[i] >> v[i] >> a[i];
		for (int i = 1; i <= m; i++)
			cin >> p[i];
		for (int i = l; i >= p[m]; i--)
			prv[i] = m;
		for (int i = m - 1; i >= 1; i--)
			for (int j = p[i + 1] - 1; j >= p[i]; j--)
				prv[j] = i;
		for (int i = 0; i <= p[1]; i++)
			nxt[i] = 1;
		for (int i = 2; i <= m; i++)
			for (int j = p[i - 1] + 1; j <= p[i]; j++)
				nxt[j] = i;
		for (int i = 1; i <= n; i++) {
			if (d[i] > p[m])
				continue;
			if (a[i] == 0) {
				if (v[i] > k)
					s.emplace_back(m, nxt[d[i]]);
			}
			else if (a[i] > 0) {
				if (v[i] > k)
					s.emplace_back(m, nxt[d[i]]);
				else {
					const int x = (k * k - v[i] * v[i]) / (a[i] * 2) + d[i] + 1;
					if (x <= p[m])
						s.emplace_back(m, nxt[x]);
				}
			}
			else if (v[i] > k) {
				const int x = (k * k - v[i] * v[i] + a[i] * 2 + 1) / (a[i] * 2) + d[i] - 1;
				if (x >= p[nxt[d[i]]])
					s.emplace_back(prv[min(l, x)], nxt[d[i]]);
			}
		}
		sort(begin(s), end(s));
		int res = m;
		for (const auto& i : s)
			if (query(i.first) == query(i.second - 1))
				add(i.first), res--;
		cout << s.size() << ' ' << res << '\n';
		s.clear();
		for (int i = 1; i <= m; i++)
			fenwick[i] = 0;
	}
	return 0;
}
